/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-empty-function */
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

let instance: any = null

function render (props: any = {}) {
  const { container } = props
  instance = createApp(App)
  instance.use(store).use(router).mount(container ? container.querySelector('#app') : '#app')
}
export async function mount (props: any) {
  render(props)
}

// 判断当前运行环境是独立运行的还是在父应用里面进行运行，配置全局的公共资源路径
if ((window as any).__POWERED_BY_QIANKUN__) {
  // eslint-disable-next-line camelcase
  const __webpack_public_path__ = (window as any).__INJECTED_PUBLIC_PATH_BY_QIANKUN__
}

// 如果是独立运行window.__POWERED_BY_QIANKUN__=undefined
if (!(window as any).__POWERED_BY_QIANKUN__) {
  render()
}

// 最后暴露的三个方法是固定的，加载渲染以及销毁
export async function bootstrap () {}

export async function unmount () {
  instance.unmount()
}

export async function update (props: any) {
  console.log('update props', props)
}
